whats wrong with this code?? :\ why it is not working properly??

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string name;
    string name2;

    cout << "Enter Name " ;

    cin >> name;
    cin.ignore('\n');
    getline (cin, name2);
    cout << "name 1 :" << name << "\n name 2: " << name2 ;

    return 0;
}